from time import sleep
from selenium.webdriver.common.by import By
from common.base import Base
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from common.readaccountinfo import ReadConfig


class MainPage(Base):

    def login(self, user_name, pwd):
        """
        登录
        :param user_name: # 输入用户名
        :param pwd:  # 输入密码
        :return:
        """
        self.send_keys("css", "#username", user_name)
        self.send_keys("css", "#password", pwd)
        self.click("css", '[name="submitbtn"]')
        self.driver.implicitly_wait(10)

    def admin_login_again(self):
        """
        输入admin账户
        输入admin密码
        点击登录
        点击进入电子班牌系统
        :return:
        """
        self.send_keys("css", "#username", ReadConfig().get_account('username'))
        self.send_keys("css", "#password", ReadConfig().get_account('password'))
        self.click("css", '[name="submitbtn"]')
        self.click("lt", "电子班牌云控中心")
        sleep(1)

    def get_loginaccount_info(self):
        """
        账号在登录中科龍威感知可视化管理系统后
        :return:获取登录的账号文本
        """
        return self.get_text("css", '#index > div > div.title > div > span')

    def goto_electroniclassbrand(self):
        """
        账号在登录中科龍威感知可视化管理系统后,
        点击进入电子班牌云控中心
        :return:
        """
        self.click("lt", "电子班牌云控中心")
        sleep(1)

    def goto_cloudcontrolcenter(self):
        """
        进入云控中心
        :return:
        """
        self.click("xp", "//*[text()='云控中心']")
        sleep(1)

    def goto_announcement(self):
        """
        进入公告管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'公告管理')]")
        sleep(1)

    def goto_video(self):
        """
        进入视频管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'视频管理')]")
        sleep(1)

    def goto_picture(self):
        """
        进入照片管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'照片管理')]")
        sleep(1)

    def goto_equipment(self):
        """
        进入设备管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'设备管理')]")
        sleep(1)

    def goto_pattern(self):
        """
        进入模式管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'模式管理')]")
        sleep(1)

    def goto_curriculumarrangement(self):
        """
        进入排课管理
        :return:
        """
        self.click("xp", "//*[contains(text(),'排课管理')]")
        sleep(1)

    def goto_maintainrepairs(self):
        """
        进入维修报修
        :return:
        """
        self.click("xp", "//*[contains(text(),'维修报修')]")
        sleep(1)

    def goto_personalcenter(self):
        """
        进入个人中心
        :return:
        """
        self.click("xp", "//*[contains(text(),'个人中心')]")
        sleep(1)

    def logout(self):
        """
        退出登录
        :return:
        """
        sleep(1)
        self.click("css", ".icon-font-xiala")
        self.driver.implicitly_wait(10)
        self.click("css", ".icon-font-logout")
        sleep(1)

    def click_submit(self):
        """
        用于页面点击提交
        :return:
        """
        self.click("xp", "//*[text()='提交']")

    def click_cancel(self):
        """
        用于页面点击取消
        :return:
        """
        self.click("xp", "//*[text()='取消']")

    def alter_location(self):
        """

        :return:返回提示消息弹窗css定位
        """
        return "div[role=alert]"

    def get_popup_text(self):
        """

        :return:获取提示消息弹窗文本
        """
        return self.get_text("css", "div[role=alert]")

    def close_popup(self):
        """
        关闭提示消息弹窗
        :return:
        """
        self.driver.execute_script('document.getElementsByClassName("el-message")[0].style="display:none"')

    def popup_accept(self):
        """
        询问弹框弹出后点击确定
        :return:
        """
        self.click("css",
                   "body > div.el-message-box__wrapper > div > div.el-message-box__btns > button.el-button.el-button--default.el-button--small.el-button--primary")

    def popup_cancel(self):
        """
        询问弹窗弹出后点击取消
        :return:
        """
        self.click("css",
                   "body > div.el-message-box__wrapper > div > div.el-message-box__btns > button:nth-child(1)")

    def click_importpopup_submit(self):
        """
        导入弹窗弹出后点击提交
        :return:
        """
        self.click("css",
                   "div.el-dialog__body > div > div.edit-group > button.el-button.submitbtn.el-button--default")

    def click_importpopup_cancel(self):
        """
        导入弹窗弹出后点击取消
        :return:
        """
        self.click("css",
                   "div.el-dialog__body > div > div.edit-group > button.el-button.cancelbtn.el-button--default")


if __name__ == '__main__':
    Login = MainPage("C", "http://192.168.58.3:8083/login")
    Login.login("admin1002", "Xwxy.123456")
    Login.goto_electroniclassbrand()
    Login.goto_cloudcontrolcenter()
    Login.goto_announcement()
    Login.goto_video()
    Login.goto_picture()
    Login.goto_equipment()
    Login.goto_pattern()
    Login.goto_personalcenter()
    Login.logout()
    Login.admin_login_again()
    Login.quit()
